package com.oil.petro.eshop.dao;

import com.oil.petro.eshop.entity.Account;
import com.oil.petro.eshop.entity.Manufacturer;
import com.oil.petro.eshop.entity.Person;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("AccountDAO")
public class AccountDAOImpl implements AccountDAO {

    @Autowired
    private SessionFactory sessionfactory;

    @Override
    public Account get(int id) {
        return (Account) sessionfactory.getCurrentSession().get(Account.class, id);
    }

    @Override
    public void delete(Account account) {
        sessionfactory.getCurrentSession().delete(account);
    }

    @Override
    public int save(Account account) {
        return (int) sessionfactory.getCurrentSession().save(account);
    }

    @Override
    public void update(Account account) {
        sessionfactory.getCurrentSession().update(account);
    }

    public Account getByLogin(String login) {

        Query query = sessionfactory.getCurrentSession().createQuery("from Account WHERE login='" + login + "'");
        System.out.println("login " + query.getQueryString());
        Account account = (Account) query.uniqueResult();
        return account;
    }
//    public void saveAccount ( Account account );
//     public Account get(int id);

}
